<?php

class ActionEdit extends BaseAction
{
    public function run()
    {
        $iUserId = Yii::app()->user->id;
    	$aCurrencies = Lot::getCurrencies();
        $aPlacementTimesNames = Lot::getPlacementTimesNames();

        $iLotNumber = Yii::app()->request->getParam('lot_number');

        if($iLotNumber)
        {
            $oLot = Lot::model()->findByAttributes(array('lot_number' => $iLotNumber));

            if($oLot)
            {
                $aTariffPlan = TariffPlan::model()->findByPk($oLot->tariff_plan_id);

                if ( Yii::app()->request->getIsPostRequest() )
                {
                    $oLot->setAttributesFromRequest('aLot');

                    if ($oLot->save())
                    {
                        Yii::app()->user->setFlash('my_lots_manage', 'Заявка под номером #'.$oLot->lot_number.' обновлена.');
                        Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/profile/my_lots'));
                    }
                }

                $this->template->aCurrencies = $aCurrencies;
                $this->template->aPlacementTimesNames = $aPlacementTimesNames;
                $this->template->aTariffPlan = $aTariffPlan;
                $this->template->oLot = $oLot;
            }
            else
            {
                Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/profile/my_lots'));
            }
        }
        else
        {
            Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/profile/my_lots'));
        }

        
    }
}